﻿
using UniFramework.Machine;
using UnityEngine;

/// <summary>
/// 流程更新完毕
/// </summary>
internal class FsmUpdaterDone : IStateNode
{
    private StateMachine _machine;

    void IStateNode.OnCreate(StateMachine machine)
    {
        _machine = machine;
    }
    void IStateNode.OnEnter()
    {
        var settings = (BootSettings)_machine.GetBlackboardValue("Settiings");
        var version = (string)_machine.GetBlackboardValue("PackageVersion");

        // 记录首包版本
        if (PlayerPrefs.GetString(PlayerPrefsKey.FirstVersion) == string.Empty)
        {
            PlayerPrefs.SetString(PlayerPrefsKey.FirstVersion, version);
            PlayerPrefs.SetString(PlayerPrefsKey.LocalVersion, version);
        }

        // 手动更新
        if (PlayerPrefs.GetInt(PlayerPrefsKey.ManualUpdate, 0) == 1)
        {
            // Reset
            PlayerPrefs.SetInt(PlayerPrefsKey.ManualUpdate, 0);

            PlayerPrefs.SetString(PlayerPrefsKey.LocalVersion, version);
            Debug.Log("更新最新版" + version);
        }

        PlayerPrefs.Save();
    }
    void IStateNode.OnUpdate()
    {
    }
    void IStateNode.OnExit()
    {
    }
}